<?php
namespace TestAdmin\Controller;
use Think\Controller;

class QuizResultController extends BaseController {

    public function index(){
        $data = M("quiz_info")->field("quiz_name")->select();
        // var_dump($data);

        $this->assign("quiz_list", $data);

        $this->display();

    }

    public function getNormalUserReportList()
    {

        $quiz_id = M("quiz_info")->where(['quiz_name' => I('quiz_name')])->find();
        $quiz_id = $quiz_id['quiz_id'];
//            $quiz_id=6;
        $data = M()->query("select calc_result.user_id, users.uid, users.username, users.email, users.age, users.sex from users, calc_result where users.uid = calc_result.user_id and users.oid = 0 and quiz_id = $quiz_id GROUP BY users.uid; ");
        //var_dump($data);



        $this->ajaxReturn($data);
    }



    public function showUserReport($quiz_name, $uid)
    {
        if ($quiz_name == '16pf_test'){
            A("Quiz/Pf16")->show_16pf($uid);
        }
        else if ($quiz_name == 'wippf_demo'){
            A("Quiz/Wippf")->show_wippf($uid);
        }
        else if ($quiz_name == 'mbti'){
            A("Quiz/Mbti")->show_mbti($uid);
        }
    }


    public function showGroupReport($quiz_name, $uid)
    {
        if ($quiz_name == '16pf_test'){
            A("Quiz/Pf16")->show_16pf_groupreport();
        }
        else if ($quiz_name == 'wippf_demo'){
            A("Quiz/Wippf")->show_wippf_groupreport($uid);
        }
        else if ($quiz_name == 'mbti'){
            A("Quiz/Mbti")->show_mbti_groupreport($uid);
        }
    }

    public function deleteReport( $quiz_name, $uid)
    {

        $quiz_id = convertToQuizId($quiz_name);


//        var_dump(D("Calc_result")->join("user_answer on calc_result.user_id = user_answer.user_id and calc_result.quiz_id = user_answer.quiz_id")
//            ->where(['calc_result.user_id' => $uid, 'calc_result.quiz_id'=>$quiz_id])->select());
//
        D("Calc_result")->deleteReport($uid, $quiz_id);

        $this->ajaxReturn(['msg' => '删除报告成功！']);
    }

    public function downloadPdf($quiz_name, $uid)
    {

        if ($quiz_name == '16pf_test'){
            $quiz_id = 6;
        }
        else if ($quiz_name == 'wippf_demo'){
            $quiz_id = 7;
        }
        else if ($quiz_name == 'mbti'){
            $quiz_id = 12;
        }

        A("Common/OutputFile")->outUserReport($uid, $quiz_id);


    }




}